﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LuceneWrap.Web.Common;
using LuceneWrap.Lib;

namespace LuceneWrap.Web
{
    public partial class Default : System.Web.UI.Page
    {
        public int Hits { get; set; }

        

        protected void Page_Load(object sender, EventArgs e)
        {
           

        }

        protected void btnBuildIndex_Click(object sender, EventArgs e)
        {

            LuceneManager<FeedResult> _luceneManager = new LuceneManager<FeedResult>();
            LuceneSearcher _luceneSearcher = new LuceneSearcher();

            //We retrieve a list of feeds from a website and get a list of FeedResult
            List<FeedResult> feeds = FeedManager.GetFeeds();
            foreach (var feed in feeds)
            {
                _luceneManager.AddItemToIndex(feed);
            }
            _luceneManager.FinalizeWriter(true);

            Response.Write("Indexed...");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //var feeds = FeedManager.GetFeeds();
            LuceneSearcher _luceneSearcher = new LuceneSearcher();
            var results = _luceneSearcher.Search<FeedResult>("Id", "http://weblogs.asp.net/scottgu/archive/2012/07/26/windows-azure-and-office-365.aspx");

            foreach (var item in results)
            {
                Response.Write(item.Id + "<br/>");
                Response.Write(item.Title + "<br/>");
                Response.Write(item.Summary + "<br/>");
            }
        }
    }
}